package com.gite.nouette.admin.implementation.controller;

import com.gite.nouette.admin.contract.controller.ICCommand;
import com.gite.nouette.admin.contract.model.ICommand;
import com.gite.nouette.admin.contract.model.command.IStateCommandActivation;
import com.gite.nouette.admin.contract.observer.IObservable;
import com.gite.nouette.admin.contract.observer.IObserver;
import com.gite.nouette.admin.contract.view.IVCommand;

public abstract class AbstractCCommand<V extends IVCommand<?>, M extends ICommand>
		extends AbstractController<V, M> implements ICCommand<V, M> {

	@Override
	public void run() {
		getM().run();
	}

	@Override
	public void execute() {
		getM().execute();
	}

	@Override
	public boolean isActive() {
		return getM().isActive();
	}

	@Override
	public void desactive() {
		getM().desactive();
		getV().desactive();
	}

	@Override
	public void active() {
		getM().active();
		getV().active();
	}

	@Override
	public IStateCommandActivation getStateActive() {
		return getM().getStateActive();
	}

	@Override
	public IStateCommandActivation getStateDesactive() {
		return getM().getStateActive();
	}

	@Override
	public void setStateActive(IStateCommandActivation stateActive) {
		getM().setStateActive(stateActive);
	}

	@Override
	public void setStateDesactive(IStateCommandActivation stateDesactive) {
		getM().setStateDesactive(stateDesactive);
	}

	@Override
	public void initActivation(IStateCommandActivation stateCommandActive,
			IStateCommandActivation stateCommandDesactive) {
		getM().initActivation(stateCommandActive, stateCommandDesactive);
	}

	@Override
	public IObservable<ICommand> getObservable() {
		return getM().getObservable();
	}

	@Override
	public void setObservable(IObservable<ICommand> observable) {
		getM().setObservable(observable);
	}

	@Override
	public void addObserver(IObserver<ICommand> observer) {
		getM().addObserver(observer);
	}

	@Override
	public int countObservers() {
		return getM().countObservers();
	}

	@Override
	public void deleteObserver(IObserver<ICommand> observer) {
		getM().deleteObserver(observer);
	}

	@Override
	public void notifyObservers() {
		getM().notifyObservers();
	}

	@Override
	public void update(ICommand observable) {
		getM().update(observable);
		initActive();
	}

	@Override
	public void initActive() {
		if (getM().isActive()) {
			getV().active();
		} else {
			getV().desactive();
		}
	}
}
